/**
 * @file Define Web application default handlers
 * 
 * @author Steve Gao<gaofu@parllay.com>
 */

const WebBaseController = require('./web-base-controller');
const SystemServices = require('../../constants').SystemServices;

class DataCollectController extends WebBaseController {

    get handlersPath() {
        return "data";
    }

    get leadBarService() {
        if (!this._leadBarService) {
            this._leadBarService = this.getSystemService(SystemServices.LEADBAR_SERVICE);
        }

        return this._leadBarService;
    }

    /**
     * Save collected lead
     * 
     * @param {String} leadflowId 
     * @param {Object} data 
     * @param {Function} parentCallback 
     * 
     * @memberOf DataCollectController
     */
    saveCollectedLead(leadflowId, data, parentCallback) {
        this.leadBarService.saveCollectedLead(leadflowId, data, (result) => {
            parentCallback(result);
        });
    }

    /**
     * Wrap the getLeadFlowSettingsByUserId method of leadBarService
     * 
     * @param {String} userId 
     * @param {Function} parentCallback 
     * 
     * @memberOf DataCollectController
     */
    getLeadFlowSettingsByUserId(userId, parentCallback) {
        this.leadBarService.getLeadFlowSettingsByUserId(userId, (result) => {
            parentCallback(result);
        });
    }

    /**
     * Wrap the saveFHTLiteResearchData method of leadBarService
     * 
     * @param {object} singleData 
     * @param {Function} parentCallback 
     * 
     * @memberOf DataCollectController
     */
    saveFHTLiteResearchData(singleData, parentCallback) {
        this.leadBarService.saveFHTLiteResearchData(singleData, (error, result) => {
            parentCallback(error, result);
        });
    }

    /**
     * Wrap the getFHTLiteResearchStatistics method of leadBarService
     * 
     * @param {object} singleData 
     * @param {Function} parentCallback 
     * 
     * @memberOf DataCollectController
     */
    getFHTLiteResearchStatistics(StatisticsResult, parentCallback) {
        this.leadBarService.getFHTLiteResearchStatistics(StatisticsResult, (error, result) => {
            parentCallback(error, result);
        });
    }

    /**
    * Wrap the getFHTLiteResearchStatistics method of leadBarService
    * 
    * @param {object} StatisticsResult
    * @param {object} lossPercent
    * @param {Function} parentCallback 
    * 
    * @memberOf DataCollectController
    */
    calculateUserResult(StatisticsResult, loss_Rate, parentCallback) {
        this.leadBarService.calculateUserResult(StatisticsResult, loss_Rate, (error, result) => {
            parentCallback(error, result);
        });
    }
}

exports.DataCollectController = DataCollectController;